<!DOCTYPE html>
<html lang='en'>

<head>
    <meta charset='UTF-8'>
    <meta name='viewport' content='width=device-width, initial-scale=1.0'>
    <meta http-equiv='X-UA-Compatible' content='ie=edge'>
    <title>Document</title>
</head>

<body>
    <div id='app'>
        <input type="text" v-color="obj" />
    </div>
    <hr>
    <div id='app2'>
        <input type="text" v-color="obj" v-focus />
    </div>
    <script src='../js/vue.js'></script>
    <script>
        //全局指令定义 一定要定义在创建实例之前  Vue.directive(指令名,{配置对象})
        Vue.directive("color", {
            bind(el, binding) {
                // binding.value是data中的obj对象  obj: { color: "red", bgcolor: "green"}
                // console.log(binding.value.color);
                // console.log(binding.value.bgcolor);
                el.style.color = binding.value.color;
                el.style.background = binding.value.bgcolor;
            }
        });

        new Vue({
            el: '#app',
            data: {
                obj: {
                    color: 'red',
                    bgcolor: 'green'
                }
            },
            methods: {},
        })

        const vm = new Vue({
            el: '#app2',
            data: {
                obj: {
                    color: 'red',
                    bgcolor: 'green'
                }
            },
            methods: {

            },
            // 局部指令配置节点
            directives: {
                // 指令名: 配置对象
                focus: {
                    inserted(el) {
                        el.focus()
                    }
                }
            }
        })


    </script>
</body>

</html>